﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.ValidationRules
{
    /// <summary>
    /// 补充说明验证类。
    /// </summary>
    public class OtherInfosRule : LValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string text = value as string;
            if (string.IsNullOrWhiteSpace(text))
                return new ValidationResult(true, null); //验证OK

            if (string.IsNullOrWhiteSpace(text))
                return new ValidationResult(false, "“补充说明”不能超过400个字符。"); //验证失败

            if (text.Length <= 400)
                return new ValidationResult(true, null); //验证OK
            else
                return new ValidationResult(false, "“补充说明”不能超过400个字符。"); //验证失败
        }

        public static string Format(string origin)
        {
            if (string.IsNullOrWhiteSpace(origin)) return "";
            return origin.Trim(new char[] { ' ', '　', '\t' });
        }
    }
}
